package com.nulldev.util.networking.npacket4.iprotocols.ncryptx;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import com.nulldev.util.networking.npacket4.nPacket;
import com.nulldev.util.networking.npacket4.extensions.PacketExtension;

public class nCryptCipherShare extends nPacket {

	private static final long serialVersionUID = -8044717583467429851L;
	private CipherOption cipher;

	public nCryptCipherShare(final nPacket packet) {
		super("ncryptx.cipher_share", packet);
	}

	public nCryptCipherShare(final CipherOption method, final PacketExtension... exts) {
		super("ncryptx.cipher_share", exts);
		this.cipher = method;
	}

	@Override
	public void onGenerate(final DataOutputStream dos) throws IOException {
		dos.writeShort(this.cipher.id());
	}

	@Override
	public void onPacket(final DataInputStream dis) throws IOException {
		this.cipher = CipherOption.get(dis.readShort());
	}

	public CipherOption getCipher() {
		return this.cipher;
	}
}
